﻿package  {
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	
	public class Control extends MovieClip {
		public static var control:Control;
		private var TotalNum:int;
		public function Control() {
			// constructor code
			control = this;
			this.addEventListener(Event.ADDED_TO_STAGE, addet);
		}
		private function addet(e:Event) {
			startBtn.addEventListener(MouseEvent.CLICK, playCL);
			soundBtn.addEventListener(MouseEvent.CLICK, soundCL);
			fullBtn.addEventListener(MouseEvent.CLICK, fullCL);
			soundBtn.buttonMode = true;
			startBtn.buttonMode = true;
		}
		public function setTimePoint(arr:Array) {
			while (timePointMc.numChildren) {
				timePointMc.removeChildAt(0);
			}
			for (var i:int = 0; i < arr.length; i++ ) {
				var mc:MovieClip = new pointPic();
				mc.x = 66 + arr[i] / TotalNum * 518;
				mc.y = 14.5;
				timePointMc.addChild(mc);
			}
		}
		private function fullCL(e:MouseEvent) {
			(root as MovieClip).flvPlay.enterFullScreenDisplayState();
		}
		private function soundCL(e:MouseEvent) {
			if (soundBtn.currentFrame == 1) {
				trace((root as MovieClip).flvPlay.volume);
				(root as MovieClip).flvPlay.volume = 0;
				soundBtn.gotoAndStop(2);
			}else {
				(root as MovieClip).flvPlay.volume = 1;
				soundBtn.gotoAndStop(1);
			}
		}
		private function playCL(e:MouseEvent) {
			if (startBtn.currentFrame == 1) {
				Main.main.as_SetPlayStop("0");
				startBtn.gotoAndStop(2);
			}else {
				Main.main.as_SetPlayStop("1");
				startBtn.gotoAndStop(1);
			}
		}
		public function setTotalTime(value:Number) {
			TotalNum = value;
			var num1:int = value / 60;
			var num2:int = value % 60;
			TotalTime_txt.text = String(num1) + ":" + String(num2);
			if (num2 < 10) TotalTime_txt.text = String(num1) + ":0" + String(num2);
			if (num1 < 10) TotalTime_txt.text = "0" + TotalTime_txt.text;
			
		}
		public function SetLoadedProgress(progress:Number) {
			this["loaded_mc"].scaleX = progress;
		}
		public function SetProgress(time:Number) {
			var progress:Number = time / TotalNum;
			this["slide_mc"].scaleX = progress;
			point_mc.x = 68 + progress * 514;
			var num1:int = time / 60;
			var num2:int = time % 60;
			curTime_txt.text = String(num1) + ":" + String(num2);
			if (num2 < 10) curTime_txt.text = String(num1) + ":0" + String(num2);
			if (num1 < 10) curTime_txt.text = "0" + curTime_txt.text;
		}
	}
	
}
